package com.tadpole.music.holder.study;

import android.app.Activity;
import android.view.View;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.Priority;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.tadpole.music.R;
import com.tadpole.music.adapter.base.BaseAdapter;
import com.tadpole.music.bean.study.StudyBean;
import com.tadpole.music.config.Constant;
import com.tadpole.music.holder.base.BaseViewHolder;
import com.tadpole.music.utils.NoDoubleClickListener;
import com.tadpole.music.view.widget.XCRoundRectImageView;
import com.white.progressview.HorizontalProgressView;

import java.util.List;

/**
 * Created By 孙岩
 * on 2020/9/10
 */
public class NowStudyViewHolder extends BaseViewHolder {
    private View itemView;
    private Activity activity;
    private BaseAdapter.OnItemClickListener onItemClickListener;
    private List<StudyBean> studyBeanList;
    private XCRoundRectImageView ivImage;
    private TextView tvName;
    public NowStudyViewHolder(Activity activity,View itemView,BaseAdapter.OnItemClickListener onItemClickListener,List<StudyBean> studyBeanList) {
        super(itemView);
        this.itemView = itemView;
        this.activity = activity;
        this.onItemClickListener = onItemClickListener;
        this.studyBeanList = studyBeanList;
    }

    @Override
    public void init(final int position) {
        ivImage = itemView.findViewById(R.id.ivImage);
        tvName = itemView.findViewById(R.id.tvName);

        RequestOptions requestOptions = new RequestOptions()
                .placeholder(R.mipmap.app_icon)
                .error(R.mipmap.app_icon)
                .priority(Priority.HIGH)
                .diskCacheStrategy(DiskCacheStrategy.ALL);

        Glide.with(activity).load(Constant.IMAGE_HEAD+studyBeanList.get(position).getImage()).apply(requestOptions).into(ivImage);
        tvName.setText(studyBeanList.get(position).getTitleName());

        itemView.setOnClickListener(new NoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                onItemClickListener.onItemClick(itemView,position);
            }
        });
    }
}
